<template>
  <div class="physiological-monitor">
    <!-- 实时数据统计 -->
    <div class="flex-shrink-0">
      <RealtimeStats />
    </div>

    <!-- 趋势图表容器 -->
    <div class="flex-1 min-h-0">
      <ParameterTrendContainer />
    </div>
    
    <!-- 提醒消息显示区域 -->
    <div v-if="recentReminders.length > 0" class="reminders-panel">
      <h3>最近提醒</h3>
      <div v-for="reminder in recentReminders" :key="reminder.id" class="reminder-item">
        <div class="reminder-title">{{ reminder.title }}</div>
        <div class="reminder-desc">{{ reminder.description }}</div>
        <div class="reminder-time">{{ formatTime(reminder.nextRemindTime) }}</div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import RealtimeStats from './components/RealtimeStats.vue'
import ParameterTrendContainer from './components/ParameterTrendContainer.vue'
import { ref, onMounted, onUnmounted } from 'vue'
import type { WebSocketMessage } from '../../utils/websocket'
import dayjs from 'dayjs'

const recentReminders = ref<WebSocketMessage[]>([])

const handleReminderReceived = (event: CustomEvent<WebSocketMessage>) => {
  const reminder = event.detail
  recentReminders.value.unshift(reminder)
  
  // 只保留最近10条提醒
  if (recentReminders.value.length > 10) {
    recentReminders.value = recentReminders.value.slice(0, 10)
  }
}

const formatTime = (timeStr: string) => {
  return dayjs(timeStr).format('YYYY-MM-DD HH:mm:ss')
}

onMounted(() => {
  window.addEventListener('reminder-received', handleReminderReceived as EventListener)
})

onUnmounted(() => {
  window.removeEventListener('reminder-received', handleReminderReceived as EventListener)
})
</script>

<style scoped>
.reminders-panel {
  margin-top: 20px;
  padding: 16px;
  background: #f8f9fa;
  border-radius: 8px;
}

.reminder-item {
  padding: 12px;
  margin-bottom: 8px;
  background: white;
  border-radius: 6px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.reminder-title {
  font-weight: 600;
  color: #303133;
  margin-bottom: 4px;
}

.reminder-desc {
  color: #606266;
  font-size: 14px;
  margin-bottom: 4px;
}

.reminder-time {
  color: #909399;
  font-size: 12px;
}
</style>
import RealtimeStats from './components/RealtimeStats.vue'
import ParameterTrendContainer from './components/ParameterTrendContainer.vue'
